#include "crate.h"

Crate::Crate(const Cube& cube,const Point& dir,const ObjectModelPtr& model)
	: 	SceneObject(cube,dir,model),
		Grabable(cube),
		Solid(cube){
	this->grabbed=false;
	this->zrotatedAngle=0;
}

Crate::~Crate(){
}

void Crate::timeStep(){
}

void Crate::notifySolidPositionChange(float vel){
	this->dimensions.translate(0,0,vel);
	this->grabZone.translate(0,0,vel);
}

void Crate::move(float dx,float dy,float dz){
	this->dimensions.translate(dx,dy,dz);
	this->grabZone.translate(dx,dy,dz);
	this->size.translate(dx,dy,dz);
}

void Crate::rotate(float angle){
	this->zrotatedAngle+=angle;
	this->dimensions.rotate(angle,this->dimensions.center(),Point(0,0,1));
}

void Crate::setModelMatrix(){
	Point tr = this->dimensions.center();
	glTranslatef(tr.x1,tr.x2,tr.x3);

	if(this->hasParent())
		this->getParent().setSubModelMatrix(Crate::name());
	glRotatef(this->zrotatedAngle*180/PI,0.0f,0.0f,1.0f);
	glScalef(this->dimensions.width(),this->dimensions.depth(),this->dimensions.height());
}
